package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfAccountDAO;
import com.AAL.Model.StatusOfAccount;
import com.AAL.Utils.HibernateUtil;

public class StatusOfAccountDAO implements IStatusOfAccountDAO {

	@Override
	public StatusOfAccount getStatusOfAccount(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfAccount statusOfAccount = (StatusOfAccount) session.load(
				StatusOfAccount.class,(short) statusID);
		return statusOfAccount;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfAccount> getAllStatusOfAccounts() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfAccount> lstStatusOfAccounts = null;
		try {
			lstStatusOfAccounts = (List<StatusOfAccount>) session.createQuery(
					"from StatusOfAccount").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfAccounts;
	}

}
